import { Application } from "pinus";
import * as mysql from 'mysql2'; // 使用命名导入，而不是默认导入

export default class DaoManager {
    public static mPool: mysql.Pool;

    public static init(app: Application) {
        const mysqlConfig = app.get('mysql');
        DaoManager.mPool = mysql.createPool({
            host: mysqlConfig.host,
            user: mysqlConfig.user,
            password: mysqlConfig.password,
            database: mysqlConfig.database,
            port: mysqlConfig.port || '3306',
            charset: 'utf8mb4',
            waitForConnections: true,
            connectionLimit: 10,   // 最大连接数
            queueLimit: 0          // 队列限制数，0 表示不限制
        });
    }
}